package com.example.maps;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

/**
 * This is the object class representing a list of location markers to be drawn 
 * on Google Maps map view. This class extends ItemizedOverlay so that it is
 * easier to manage location markers.
 * 
 * @author Jacob Cheng
 *
 */

public class HelloItemOverlay extends ItemizedOverlay<OverlayItem>{
	
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;

	public HelloItemOverlay(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
	}
	
	public HelloItemOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  mContext = context;
	}
	
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	public void addOverlay(ArrayList<OverlayItem> overlay) {
	    mOverlays.addAll(overlay);
	    populate();
	}
	
	/**
	 * When a location marker gets tapped, display an alert dialog containing its title and information.
	 */
	@Override
	protected boolean onTap(int index) {
	  OverlayItem item = mOverlays.get(index);
	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
	  dialog.setTitle(item.getTitle());
	  dialog.setMessage(item.getSnippet());
	  dialog.show();
	  return true;
	}
	
	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mOverlays.get(i);
	}
	
	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mOverlays.size();
	}
	
	
}
